package scoutobahn.xml;

import java.util.Map;

/**
 * Base class for all elements of Osm Xml dump.
 * @author mark
 *
 */
public abstract class OsmItem {
    /**
     * The id of the item.
     */
    private final long id;
    private final Map<String, String> tags;
    /**
     * Construct's a new OsmItem with the given id.
     * @param newId The id
     * @param newTags The tags of this osm item
     */
    public OsmItem(final long newId,
            final Map<String, String> newTags) {
        this.id = newId;
        this.tags = newTags;
    }
    /**
     * Returns the Id of this OsmItem.
     * @return The id
     */
    public long getId() {
        return this.id;
    }
    /**
     * Tests weather this OsmItem has a tag with the given key.
     * @param key The key of the tag
     * @return true If there is a tag with the given key
     */
    public boolean hasTag(final String key) {
        return this.tags.containsKey(key);
    }
    /**
     * Returns the tag value associated with the given key.
     * @param key The key of the tag
     * @return The value of the tag
     */
    public String getTag(final String key) {
        return this.tags.get(key);
    }
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (int) (id ^ (id >>> 32));
        return result;
    }
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        OsmItem other = (OsmItem) obj;
        if (id != other.id) {
            return false;
        }
        return true;
    }
}
